<template>
  <div style="padding: 10px">
    <div style="margin: 10px 0">
      <el-input v-model="keyword" placeholder="请输入关键字" style="width: 20%" clearable />
      <el-button type="primary" style="margin-left: 5px" @click="searchCourse">查询</el-button>
    </div>
    <el-table :data="tableData" border style="width: 100%" stripe>
      <el-table-column fixed prop="name" label="课程名" sortable/>
      <el-table-column fixed prop="number" label="课程编号"/>
      <el-table-column prop="school" label="开课院系"/>
      <el-table-column prop="hour" label="学时"/>
      <el-table-column prop="credit" label="学分"/>
      <el-table-column prop="teacher" label="任课教师"/>
      <el-table-column prop="description" label="课程介绍"/>
      <el-table-column prop="time" label="上课时间"/>
      <el-table-column prop="place" label="上课地点"/>
      <el-table-column prop="capacity" label="选课容量"/>
      <el-table-column fixed="right" label="操作" width="120">
        <template #default="scope">
          <el-button type="text" @click="handleApply(scope.row.number)">申请</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import request from "@/utils/request";

export default {
  name: "CourseApply",
  components:{

  },
  data(){
    return{
      tableData:[],
      keyword:'',
    }
  },
  created() {
    this.load()
  },
  methods: {
    load(){
    },
    searchCourse(){
      request.get("http://localhost:8082/course/courseList?name="+this.keyword).then(res=>{
        this.tableData = res.data

      })
    },
    handleApply(number){
      request.post("http://124.70.179.188:8082/selCourse/applyCourse?courseid="+number+"&stunum="+localStorage.getItem("userid")).then(res => {
        if (res.code === '200') {
          this.$message.success("申请成功")
          this.dialogVisible = false
          this.load()
        } else {
          this.$message.error("申请失败")
        }
      })
    },
  }
}
</script>

<style scoped>

</style>